using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_WFEVENTDEF
    {
        public void SetUpNewRow(ref DataRow dwReturn)
        {

            switch (app.company)
            {
                case "YGR":
                case "YCC":
                default:
                    #region=========
                    dwReturn["MANDANT"] = "00";
                    dwReturn["ROWNID"] = INTEXDBC.GetSeq();
                    dwReturn["WFTYPE"] = "M  ";
                    dwReturn["WFCLASS"] = "   ";
                    dwReturn["WFEVENTS"] = "            ";
                    dwReturn["WFEDES"] = "                                        ";
                    dwReturn["NEWUSER"] = app.User;
                    dwReturn["NEWTIME"] = date;
                    dwReturn["CHGUSER"] = app.User;
                    dwReturn["CHGTIME"] = "20140917";
                    dwReturn["WFEHANDLER"] = "                    ";
                    #endregion
                    break;
            }
        } 
        public void InsertICC_WFEVENTDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            dwData["NEWUSER"] = app.User;
            dwData["NEWTIME"] = date;
            or1 = OracleDB.CreateCommand();  
            or1.CommandText = "INSERT INTO ICC_WFEVENTDEF(MANDANT,ROWNID,WFEVENTS,WFEDES,WFEHANDLER,NEWUSER,NEWTIME,CHGUSER,CHGTIME)"
                        + " VALUES (:MANDANT:,:ROWNID:,:WFEVENTS:,:WFEDES:,:WFEHANDLER:,:NEWUSER:,:NEWTIME:,:CHGUSER:,:CHGTIME:)";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData); 
            Connect2Proxy(or1);
        }

        public DataSet QueryICC_WFEVENTDEF(DataRow dwData, int option = 1)
        {

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTDEF WHERE  ROWNID=:ROWNID:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    SResult = Connect2Proxy(or1);
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTDEF WHERE  MANDANT=:MANDANT: AND WFCLASS=:WFCLASS:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    SResult = Connect2Proxy(or1);
                    break;
                case 3:
                    or1.CommandText = "SELECT DISTINCT E.* FROM ICC_WFEVENTDEF E LEFT JOIN ICC_WFSUBSCRIBER S"
                        + " ON E.MANDANT=S.MANDANT AND E.WFEVENTS=S.WFEVENTS"
                        + " WHERE S.MANDANT=:MANDANT: AND S.WFEUSER=:WFEUSER:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    SResult = Connect2Proxy(or1);
                    break;
                case 4:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTDEF WHERE  MANDANT=:MANDANT:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    SResult = Connect2Proxy(or1);
                    break;
                case 5:  
                    SResult = QWFD05(dwData);
                    break;
                default:
                case 9999:
                    or1.CommandText = "SELECT WFEVENTS AS KEY,WFEDES AS DES,M.* FROM ICC_WFEVENTDEF M";
                    SResult = Connect2Proxy(or1);
                    break;
            } 
            SResult.Tables[0].TableName = TableName;

            return SResult;
        }
        public DataSet QWFD05(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT WFEVENTS AS KEY,WFEDES AS DES,M.* FROM ICC_WFEVENTDEF M WHERE MANDANT=:MANDANT: " + dwData["WFCLASS"].ToString();
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public void DeleteICC_WFEVENTDEF(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_WFEVENTDEF WHERE  ROWNID=:ROWNID:"; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }
            Connect2Proxy(or1);
        }
        public void UpdateICC_WFEVENTDEF(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            dwData["CHGUSER"] = app.User;
            dwData["CHGTIME"] = date;

            or1.CommandText = "UPDATE ICC_WFEVENTDEF SET MANDANT=:MANDANT:, ROWNID=:ROWNID:, WFTYPE=:WFTYPE:, WFCLASS=:WFCLASS:, WFEVENTS=:WFEVENTS:, WFEDES=:WFEDES:, NEWUSER=:NEWUSER:, NEWTIME=:NEWTIME:, CHGUSER=:CHGUSER:, CHGTIME=:CHGTIME:, WFEHANDLER=:WFEHANDLER:,NEXTEVENTS1=:NEXTEVENTS1:,NEXTEVENTS2=:NEXTEVENTS2:,NEXTEVENTS3=:NEXTEVENTS3:,DEFCONTROL1=:DEFCONTROL1:,DEFCONTROL2=:DEFCONTROL2:,DEFCONTROL3=:DEFCONTROL3:"
                        + " WHERE    ROWNID=:ROWNID: ";

            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

            Connect2Proxy(or1);
        }
    }
}
